<#if !data??>
<div class="alert alert-danger" role="alert">
	<strong>警告！</strong>
	无法创建资金信息，请联系管理员！
</div>
<#else>
<form class="form-money-new" action="${request.contextPath}/money/new" method="post">
	<div class="row">
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null-star">*</span>
							${data.name}
						</div>
					</div>
					<input type="hidden" name="contract.id" value="${data.contract.id}">
					<input type="hidden" name="payOut" value="${data.payOut?string('true','false')}">
					<input type="hidden" name="gaveBack" value="${(data.gaveBack?string('true','false'))!''}">
					<input type="hidden" name="inAccount" value="${data.inAccount}">
					<input type="hidden" name="source" value="${data.source}">
					<input type="hidden" name="invoice" value="${data.invoice?string('true','false')}">
					<input type="hidden" name="name" value="${data.name}">
					<input type="text" class="form-control not-empty number" name="total" placeholder="填写金额">
					<div class="input-group-addon">元</div>
				</div>
			</div>
		</div>
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null-star">*</span>
							${data.payOut?string('支出日期','收取日期')}
						</div>
					</div>
					<input type="text" class="form-control not-empty datetimepicker" name="time" data-format="yyyy-MM-dd" data-foot="false" placeholder="请选择日期" readonly="readonly">
				</div>
			</div>
		</div>
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null-star">*</span>
							${data.payOut?string('回收日期','退回日期')}
						</div>
					</div>
					<input type="text" class="form-control not-empty datetimepicker" name="backTime" data-format="yyyy-MM-dd" data-foot="false" placeholder="请选择日期" readonly="readonly">
				</div>
			</div>
		</div>
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">备注</div>
					</div>
					<textarea rows="5" class="form-control" name="remark" placeholder="最多1000个汉字"></textarea>
				</div>
			</div>
		</div>
	</div>

	<div class="row">
		<div class="col-md-12 text-right">
			<div class="btn btn-primary btn-sm btn-submit">确定</div>
			&nbsp;
			<div class="btn btn-default btn-sm" onclick="$.suredy.closeModal();">关闭</div>
		</div>
	</div>
</form>

<script type="text/javascript">
	$(function() {
		$.suredy.datetimepicker.init();

		$('form.form-money-new .btn-submit').on('click', function() {
			var form = $('form.form-money-new');

			// 校验表单
			if (!$.suredy.formChecker(form)) {
				return false;
			}

			var $this = $(this);
			var okBtn = $('form.form-money-new .btn-submit');

			if (okBtn.hasClass('disabled'))
				return false;

			okBtn.addClass('disabled');

			form.ajaxSubmit({
				dataType : "json",
				success : function(data, textStatus, jqXHR) {
					if (!data || !data.success) {
						alert(data.msg || '无法保存资金信息！');
						okBtn.removeClass('disabled');
						return false;
					}

					refresh();

					$.suredy.closeModal();
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert('无法保存资金信息！\n' + errorThrown);
					okBtn.removeClass('disabled');
					return false;
				}
			});
		});
	});
</script>
</#if>
